<template>
	<view class="pd20 page-body">
		<view class="block mt20 address">
			<view class="icon location "></view>
			<view class="address-info">
				<view><text class="name">收件人</text><text class="contact">{{row.mobile}}</text></view>
				<view>{{row.address}}</view>
			</view>
		</view>
		<view class="row block" @click="goToGoods(row.gid)">
			<view class="type">{{row.status_description}}</view>
			<view class="order-info" >
				<view class="left">
					<image :src="row.goods_thumb"></image>
				</view>
				<view class="right">
					<view class="name">
						{{row.goods_name}}
					</view>
					<view class="spec">{{row.attr_value_str}}</view>
					<view class="price-number">
						<!-- ￥<view class="price">{{row.goods_amount}}</view> -->
						x<view class="number">{{row.goods_num}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="block goods-sum">
			<view class="line-sb ">
				<view>商品金额</view>
				<view>￥{{row.goods_amount}}</view>
			</view>
			<view class="line-sb ">
				<view>运费</view>
				<view>￥{{row.shipping_fee}}</view>
			</view>
			<view class="line-sb underline">
				<view>订单总价</view>
				<view>￥{{row.order_amount}}</view>
			</view>
			<view class="line-sb underline">
				<view>优惠</view>
				<view>￥{{row.coupon_amount}}</view>
			</view>
			<view class="line-sb underline">
				<view>实付款</view>
				<view class="thecolor">￥{{row.payable_amount}}</view>
			</view>
		</view>
		<view class="block order-msg">
			<view class="h3">订单信息</view>
			<view class="line-defalut" ><text class="text">订单编号：</text><text selectable>{{row.order_sn}}</text></view>
			<view class="line-defalut" v-if="row.add_time"><text class="text">创建时间：</text>{{row.add_time}}</view>
			<view class="line-defalut" v-if="row.pay_status==2&&row.pay_time"><text class="text">付款时间：</text>{{row.pay_time}}</view>
			<!-- <view class="line-defalut" v-if="row.shipping_status==1||row.shipping_status==2"><text class="text">发货时间：</text>{{row.delivery_time}}</view> -->
			<view class="line-defalut" v-if="(status==3||status==6)&&row.confirm_time" ><text class="text">成交时间：</text>{{row.confirm_time}}</view>
		</view>
		<view class="btns btn-bottom">
			<block v-if="status=='0'">
				<view class="default" @tap="cancelOrder(row.id)">取消订单</view>
				<view class="pay" @tap="toPayment(row.id)">付款</view>
			</block>
			<block v-if="status=='1'">
				<view class="pay" @tap="Applyreturns(row.id)">我要退款</view>
			</block>
			<block v-if="status=='2'">
				<view class="default" @tap="showLogistics(row.id)" v-if="row.kuaidi_num">查看物流</view>
				<view class="pay" @tap="Comfirmreceipt(row.id)">确认收货</view>
				<view class="pay" @tap="Applyreturns(row.id)">我要退款</view>
			</block>
			<block v-if="status=='3'">
				<view class="default" @tap="evaluation(row)">评价</view>
			</block>
			<!-- <block v-if="status=='6'">
				<view class="default">再次购买</view>
			</block> -->
			<block v-if="status=='4'">
				<view class="default" @tap="checkSchedule(row.rid)" >查看进度</view>
				<!-- <view class="default" @tap="fillLogistics(rid)" >填写物流</view>
				<view class="pay" @tap="cancelRefunds(rid)" v-if="row.shipping_status == 3">取消退货</view> -->
			</block>
		</view>
	</view>
</template>

<script>
	var that;
	export default{
		data(){
			return{
				row:"",
				status:0,//0:待付款,1:待发货，2:待收货，3:待评价，4:退款货，5:订单取消，6:订单完成;7:订单无效
				rid:"",
				nid:""
			}
		},
		onLoad(options){
			that=this;
			this.oid = options.oid;
			if(options.nid){
				this.nid = options.nid
			}
			// if(options.rid){
			// 	this.rid = options.rid;
			// }
			this.getOrderDetail()
		},
		methods:{
			getOrderDetail(){
				this.$https.POST({
					url:'/order/orderDetails',
					data:{
						oid:that.oid,
						nid:that.nid
					},
					success(res){
						let orderData = res.data;
						that.initData(orderData)
					}
				})
			},
			initData(orderData){
				if(orderData.order_status==0){
					if(orderData.pay_status==0){
						orderData.status_description = "等待付款";
						that.status = 0
					}else{
						orderData.status_description = "订单无效"
						that.status = 7
					}
				}else if(orderData.order_status==1){ //1已支付
					if(orderData.shipping_status==0&&orderData.pay_status==2){ //待发货
						orderData.status_description = "等待商家发货";
						that.status = 1;
					}
					if(orderData.shipping_status==1&&orderData.pay_status==2){ //待收货
						orderData.status_description = "商家已发货"
						that.status = 2
					}
					// if(orderData.shipping_status==2&&orderData.pay_status==2&&orderData.is_comment==0){ //待评价
					// 	orderData.status_description = "等待用户评价"
					// 	that.status = 3
					// }
					
				}else if(orderData.order_status==2){ 
					orderData.status_description = "订单已取消"
					that.status = 5;
				}else if(orderData.order_status==3){ 
					orderData.status_description = "订单无效";
					that.status = 7;
				}else if(orderData.order_status==4){
					if(orderData.is_comment!=0){
						orderData.status_description = "订单已完成"
						that.status = 6
					}
					if(orderData.is_comment==0&&orderData.shipping_status==2){
						that.status = 3
						orderData.status_description = "等待用户评价"
					}
				}else if(orderData.order_status==5){ //退货中
					that.status = 4;
					if(orderData.shipping_status==3){
						orderData.status_description = "商品退货处理中"
					}
				}else if(orderData.order_status==6){
					that.status = 4;
					if(orderData.shipping_status==4){
						orderData.status_description = "退货完成"
					}
				}
				that.row = orderData;
			},
			showLogistics(row){
				let goodsmsg = encodeURIComponent(JSON.stringify(row));
				uni.navigateTo({
					url: "/pages/user/order_list/order/logistics?goodsmsg="+goodsmsg
				})
			},
			remindDeliver(row){
				uni.showToast({
					title:'已提醒商家发货'
				})
			},
			cancelOrder(oid){
				uni.showModal({
					title: '取消订单',
					content: '确定取消此订单？',
					success: (res)=>{
						if (res.confirm) {
							that.$https.POST({
								url:'/order/closeOrder',
								data:{
								  oid: oid,
								},
								success(res){
									that.$showToast("订单取消成功");
									that.row.order_status = 2;
									that.initData(that.row)
								}
							})
						} else if (res.cancel) {
						}
					}
				});
			},
			toPayment(oid){
				uni.navigateTo({
					url:"/pages/pay/payment/payment?oid="+oid
				})
			},
			Comfirmreceipt(row){
				uni.showModal({
					title: '确认收货',
					content: '是否确认收货？',
					success: (res) => {
						if (res.confirm) {
							that.$https.POST({
								url:'/order/confirmReceivingGoods',
								data:{
								  oid: oid,
								},
								success(res){
									that.$showToast("确认收货成功");
									that.row.order_status = 4;
									that.row.is_comment = 0;
									that.row.shipping_status = 2
									that.initData(that.row)
								}
							})
						} else if (res.cancel) {
							
						}
					}
				});
			},
			Applyreturns(oid){
				uni.navigateTo({
					url:'./apply_returns?oid='+oid
				})
			},
			/* 退款详情 */
			checkSchedule(rid) {
				uni.navigateTo({
					url: "./return_schedule?rid=" + rid
				})
			},
			goToGoods(gid){
				uni.navigateTo({
					url:"/pages/goods/goods?id="+gid
				})
			},
			evaluation(row) {
				let rowg = {
					goods_thumb:row.goods_thumb,
					goods_name:row.goods_name,
					attr_value_str:row.attr_value_str,
					id:row.id,
					gid:row.gid
				}
				let goodsmsg = encodeURIComponent(JSON.stringify(rowg));
				uni.navigateTo({
					url: "./evaluation?goodsmsg=" + goodsmsg
				})
			},
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #f3f3f3;
	}
	.schedule{
		height:160upx;background: #e65339; color: #fff;font-size: 30upx; display: flex; align-items: center; box-sizing: border-box; padding: 0 20upx;
	}
	.pd20{padding:0 20upx;}
	.block{
		padding: 10upx 20upx;
		border-radius: 10upx;
		background-color: #fff;
		margin-bottom: 20upx;
	}
	.line-sb{display: flex;justify-content: space-between;}
	.address{
		display: flex;align-items: center; padding:20upx;
		.address-info{
			margin-left: 20upx; line-height: 40upx;font-size: 28upx;
			.contact{color: #888;margin-left: 20upx;}
		}
	}
	.goods-sum{
		font-size: 26upx;color: #808080; line-height: 50upx;
		.underline{font-size:28upx ;color: #333;}
	}
	.order-msg{
		.h3{font-size: 30upx;color: #333333;line-height: 70upx;}
		.line-defalut{
			display: flex;font-size: 26upx;color: #666;line-height: 60upx;
			.text{width:160upx;}
		}
	}
	/* 商品样式 */
	.row{
		margin-top: 20upx;
		
		.type{
			font-size: 26upx;
			color: #ec652f;
			height: 50upx;
			display: flex;
			align-items: center;
		}
		.order-info{
			width: 100%;
			display: flex;
			.left{
				flex-shrink: 0;
				width: 25vw;
				height: 25vw;
				image{
					width: 25vw;
					height: 25vw;
					border-radius: 10upx;
				}
			}
			.right{
				width: 100%;
				margin-left: 10upx;
				position: relative;
				.name{
					width: 100%;
					font-size: 28upx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
				}
				.spec{
					color: #a7a7a7;
					font-size: 22upx;
					padding-top: 6upx;
				}
				.price-number{
					position: absolute;
					bottom: 0;
					width: 100%;
					display: flex;
					justify-content: flex-end;
					font-size: 22upx;
					color: #333;
					display: flex;
					align-items: flex-end;
					.price{
						font-size: 24upx;
						margin-right: 5upx;
					}
					
				}
			}
		}
	}
	.btn-bottom{background: #fff;position: fixed;bottom: 0;left: 0;width: 100%;padding-right:20upx ;box-sizing: border-box;}
	.btns{
		// height: 80upx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		view{
			min-width: 120upx;
			height: 50upx;
			padding: 0 20upx;
			border-radius: 50upx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 28upx;
			margin-left: 20upx;
			margin-top: 20upx;
			margin-bottom: 20upx;
		}
		.default{
			border: solid 1upx #ccc;
			color: #666;
			
		}
		.pay{
			border: solid 1upx #ec652f;
			color: #ec652f;
		}
	}
</style>
